import React, { PureComponent } from 'react'
import '../../../css/base-detail.scss'
import Table from 'antd/lib/table'
import '../../../css/table.scss'
import { scale } from '../chart/util/common'

class BaseTable extends PureComponent {
    constructor () {
        super()
        this.state = {
            height: 300
        }
    }

    resize = () => {
        const {table} = this.refs
        const height = table.clientHeight - 64 * scale - 20*scale
        this.setState({
            height
        })
    }

    componentDidMount () {
        this.resize()
        window.addEventListener('resize', this.resize)
    }

    componentWillUnmount () {
        window.removeEventListener('resize', this.resize)
    }

    render () {
        let page = false
        if(this.props.dataSource.length > 15 && {pageSize: 15} && (this.props.page !== false)){
            page = {pageSize: 15}
        }
        return (
            <div className="base-table-container" ref='table' style={{width: '100%', height: 'calc(100% - 1rem)'}}>
                <Table {...this.props} scroll={{y: this.state.height}} pagination={page}/>
            </div>
        )
    }

}

export default BaseTable